package com.hellenic.servlets;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.hibernate.SessionFactory;

import com.hellenic.mod.ReservationMod;

@SuppressWarnings( "serial" )
public class ListingReservation extends HttpServlet {
    private static final String ATTR_DAO_FACTORY = "sessionF";
    private static final String ATTR_LIST_RESA   = "lesReservations";
    private static final String VUE              = "/WEB-INF/admin/reservations.jsp";

    private ReservationMod         reservationM;

    public void init() throws ServletException {
        // Récupération de l'objet SessionFactory
        SessionFactory sf = (SessionFactory) getServletContext().getAttribute( ATTR_DAO_FACTORY );

        // intanciation de la classe metier
        reservationM = new ReservationMod( sf );
        System.out.println( "Message : Initialisation servlet Reservation" );
    }

    public void doGet( HttpServletRequest request, HttpServletResponse response ) throws ServletException, IOException {
        request.setAttribute( ATTR_LIST_RESA, reservationM.listingResa( request ) );
        this.getServletContext().getRequestDispatcher( VUE ).forward( request, response );
    }

    public void doPost( HttpServletRequest request, HttpServletResponse response ) throws ServletException, IOException {

    }
}
